<?php
namespace app\api\controller;

use app\home\model\Images;

class Adv
{
    public function index()
    {
        return json(Images::where('image_kind', '1')->select());
    }
    public function add(){
        $data = request()->param();
        $adv = new Images ;
        $adv['image_kind'] = 1;
        $adv->save($data);
        return json(['adv'=>Images::find($adv->id)]);
    }
    public function edit(){
        $data = request()->param();
        $adv = Images::find($data['id']);
        $res = $adv->save([
            'image' => $data['image'],
            'image_url' => $data['image_url'],
            'order' => $data['order'],
            'alt'=>$data['alt'],
        ]);
        return json($res);
    }
    public function del(){
        $adv_id = request()->param('id');
        return Images::destroy($adv_id);
    }
}
